package spike.s003.sqlflow.entity;

import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

/**
 * Created by ylyang on 02/04/2017.
 */
public class StudentEntity {
    private String studentID;
    private String name;
    private Integer age;
    private Boolean gender;
    private Date createTime;

    private List<StudentCourseEntity> studentCourseEntities;
    private List<StudentQQEntity> studentQQEntities;


    public String getStudentID() {
        return studentID;
    }

    public void setStudentID(String studentID) {
        this.studentID = studentID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Boolean isGender() {
        return gender;
    }

    public void setGender(Boolean gender) {
        this.gender = gender;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public List<StudentCourseEntity> getStudentCourseEntities() {
        return studentCourseEntities;
    }

    public void setStudentCourseEntities(List<StudentCourseEntity> studentCourseEntities) {
        this.studentCourseEntities = studentCourseEntities;
    }

    public List<StudentQQEntity> getStudentQQEntities() {
        return studentQQEntities;
    }

    public void setStudentQQEntities(List<StudentQQEntity> studentQQEntities) {
        this.studentQQEntities = studentQQEntities;
    }

    public static class BeanRowMapper {
        private static final BeanPropertyRowMapper<StudentEntity> MAPPER = BeanPropertyRowMapper.newInstance(StudentEntity.class);

        public static StudentEntity mapRow(ResultSet rs) throws SQLException {
            String s = rs.getString("student_ID");

            StudentEntity studentEntity = MAPPER.mapRow(rs, rs.getRow());
            studentEntity.setStudentID(s);
            studentEntity.setName(rs.getString("name"));
            studentEntity.setAge(rs.getInt("age"));
            studentEntity.setGender(rs.getBoolean("gender"));
            studentEntity.setCreateTime(rs.getDate("create_time"));
            return studentEntity;
        }
    }

    @Override
    public String toString() {
        return "StudentEntity{" +
                "studentID='" + studentID + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                ", createTime=" + createTime +
                ", studentCourseEntities=" + studentCourseEntities +
                ", studentQQEntities=" + studentQQEntities +
                '}';
    }
}
